<style type="text/css">
    .table thead tr th, .table tbody tr td {
        text-align: center;
    }
</style>
<div id="content">
    <!-- <link href="/media/vendor/css/ui-lightness/jquery-ui-1.10.4.custom.css" rel="stylesheet"> -->
    <script src="/media/vendor/js/jquery-1.10.2.js"></script>
    <script src="/media/js/leadtime/leadreport.js"></script>

    <!-- <script src="/media/vendor/js/jquery-ui-1.10.4.custom.js"></script> 
    <script src="/media/vendor/js/jquery.ui.datepicker-zh-TW.js"></script> 
    <script src="/media/vendor/artdialog/jquery.artDialog.js"></script>
    <link rel="stylesheet" href="/media/vendor/artdialog/skins/default.css" type="text/css" media="all">
    <script src="/media/vendor/artdialog/jquery.artDialog.js"></script> 
    <script src="/media/js/jquery.json-2.4.js"></script> -->
    <div id="formSearch" class="form-horizontal">
        <form action="/leadreport" method="GET">
            <div style="margin-bottom:10px; display: inline-block;">
                <span class="asd">供应商</span>
                <input style=" margin-right:10px;width:164px;" type="text" class="input-xlarge supplier" name="supplier"
                       value="<?php echo htmlspecialchars(isset($_GET['supplier'])?$_GET['supplier']:'',ENT_QUOTES,'UTF-8'); ?>">
            </div>
            <div style="margin-bottom:10px; display: inline-block;">
                <span class="asd" for="input01">sku</span>
                <input style=" width:164px; margin-right:10px;" type="text" class="input-xlarge sku" name="skuName"
                       autocomplete="off"
                       value="<?php echo htmlspecialchars(isset($_GET['skuName'])?$_GET['skuName']:'',ENT_QUOTES,'UTF-8'); ?>">
            </div>
            <div style="margin-bottom:10px; display: inline-block;">
                <span class="asd">负责人</span>
                <input type="text" class="input-xlarge purchaser" style="width:164px;" name="userName"
                       value="<?php echo htmlspecialchars(isset($_GET['userName'])?$_GET['userName']:User::active_user()->nick,ENT_QUOTES,'UTF-8'); ?>">
                <button style="margin-left:10px;" class="btn btn-info" type="submit">查询</button>
                <button class="btn btn-inverse" type="reset">重置</button>
            </div>
            <div style="margin-bottom:10px; display: inline-block;">
                <button class="btn btn-success" onclick="leadreportObj.downLoad(); return false;">所有供应商SKU交期下载</button>
                <button class="btn btn-success" onclick="lastPurchaseObj.lastPurchase(); return false;">最近采购供应商SKU交期下载</button>
                <button class="btn btn-success" onclick="sku_leadreportObj.sku_download(); return false;">供应商SKU最大第二交期值下载</button>
                <button class="btn btn-success" onclick="goMaxMinEveObj.goMaxMinEve(); return false;">最近采购去掉最大最小平均交期下载</button>
            </div>
        </form>


        <?php
        if(isset($dataList)){
            ?>
            <table class="table table-hover ">
                <thead>
                <tr style=" background-color:#4EA392; color:#fff;">
                    <th> SKU</th>
                    <th> 商品名</th>
                    <th> 供应商(ID::全称)</th>
                    <th> 交期</th>
                    <th> 操作</th>
                </tr>
                </thead>
                <tbody>
                <?php
                $cacheSku = array();
                $cacheSu = array();
                foreach($dataList as &$v){
                    $cacheSku[$v['sku']]  = & $v['sku'];
                    $cacheSu[$v['su_id']] = & $v['su_id'];
                }
                $temp = json_decode(skusystemapi::getMoreSkuCnname('("'.join('", "',$cacheSku).'")'),true); //无可奈何的写法
                $cacheSku = array();
                if($temp){
                    foreach($temp as &$v){
                        $cacheSku[$v['sku']] = & $v['name'];
                    }
                }

                $temp = newerpclientapi::getSuppliernameBatch($cacheSu); //亲,系统好好设计下呗
                $cacheSu = array();
                if($temp){
                    foreach($temp as &$v){
                        $cacheSu[$v['id']] = & $v['name'];
                    }
                }

                foreach($dataList as $k => &$v){
                    echo "<tr>
                            <td> {$v['sku']} </td>
                            <td> {$cacheSku[$v['sku']]} </td>
                            <td> {$v['su_id']}::{$cacheSu[$v['su_id']]} </td>
                            <td> {$v['ldt_sec']} </td>
                            <td><button class='btn btn-mini btn-info open_close'>
                                <i class='icon-hand-down'>展开</i>
                                </button></td>
                        </tr>
                        <tr style='display: none'>
                            <td colspan='5'>
                                <table class='table'>
                                    <input type='hidden' name='h_sku' class='h_sku' value='{$v['sku']}'/>
                                    <input type='hidden' name='h_su_id' class='h_su_id' value='{$v['su_id']}'/>
                                    <div class='highcharts_content'></div>
                                </table>
                            </td>
                        </tr>";
                }
                ?>

                </tbody>
            </table>
            <?php
            echo $pagination;
        }
        ?>
    </div>
</div>
<script src="<?php echo URL::base() ?>media/vendor/js/highcharts.js"></script>
<script src="<?php echo URL::base() ?>media/vendor/js/exporting.js"></script>
<script type="text/javascript">
    $(function () {
        $('.open_close').on('click', function () {
            $(this).parents("tr").next().toggle();
            var t = $(this).parents("tr").next();
            var attr = $(this).parents("tr").next().attr("style");
            if (attr == "display: table-row;" || attr == '') {
                var sku = $(this).parents("tr").next().find("input[name='h_sku']").val();
                var su_id = $(this).parents("tr").next().find("input[name='h_su_id']").val();
                $.get("/leadreport/highcharts",
                    {sku: sku, su_id: su_id},
                    function (data) {
                        var obj = jQuery.parseJSON(data);
                        t.find("div[class='highcharts_content']").html(obj.view);
                    }
                )
            }
        });
    })
</script>